<template>
  <div class="index">
      <div class="crumbs wrapa flex">
            <router-link to="/" class="p">首页</router-link>
            <router-link class="p" to="/service/activity" v-if="parent.meta">>活动中心</router-link>
            <div class="p">>{{title}}</div>
          </div>

    <div class="wrap flex-bett">

      <div class="content">
        <div class="top">
          <div class="title">
              {{datas.title}}
          </div>
          <div class="date">浏览 {{datas.viewed?datas.viewed:0}} 次</div>
        </div>
        <div class="mian" v-html="datas.content">

        </div>

      </div>
      <div class="rightz">
        <div class="right">
          <div class="right-title flex"><b></b><p>报名</p></div>
          <div class="p flex"><b>报名人数：</b><p>已有{{datas.count}}人报名</p></div>
          <div class="p flex"><b>活动时间：</b><p>{{datas.startTime1}} — {{datas.endTime1}}</p></div>
          <div class="p flex"><b>报名时间：</b><p>{{datas.signStartTime1}} — {{datas.signEndTime1}} </p></div>
          <div class="p flex"><b>活动地点：</b><p>{{datas.activeAddress}}</p></div>
            <div class="qrcode" ref="qrCodeUrl"></div>
            <div class="btn" @click="togNav('/service/activityform?id='+id)">报名参加</div>
        </div>
        <div class="right-scroll">
          <div class="right-title flex"><b></b><p>已报名列表</p></div>
        <div id="box">
            <ul id="con1" ref="con1" :class="{anim:animate==true}">
                <li v-for='(item,index) in datas.signList' :key="index" class="flex-bet"><p>{{item.phone}}</p><p>{{item.name}}</p></li>
            </ul>
        </div>
        </div>
      </div>


    </div>
  </div>
</template>
<script>
import { getActivityDetail } from "@/api/service/service";
import QRCode from 'qrcodejs2'
export default {
  name: "index",
  data() {
    return {
      parent: {}, //获取父路由信息
      title: "",
      datas:{},
      id:"",
      route:{},
      animate:false,
      items:[

      ]
    };
  },

  created() {
    this.id=this.getQueryString("id");
    this.getInfomationDetailapi()

  },
  mounted() {
    console.log(window.location.href)
    var qrcode = new QRCode(this.$refs.qrCodeUrl, {
            text: window.location.href, // 需要转换为二维码的内容
            width: 150,
            height: 150,
            colorDark: '#5b6b73',
            colorLight: '#ffffff',
            correctLevel: QRCode.CorrectLevel.H
        })
    this.route = this.$route;
      this.parent = this.$route.matched[0];
      this.title = this.$route.meta.title;
  },
  methods: {
    togNav(e) {
      this.$router.push(e);
    },
    getQueryString(name) {
      let reg = `(^|&)${name}=([^&]*)(&|$)`;
      let r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    getInfomationDetailapi() {
      getActivityDetail({ id: this.id }).then((res) => {
        console.log(res)
        res.datas.signStartTime1 = this.renderTime(res.datas.signStartTime)
        res.datas.signEndTime1 = this.renderTime(res.datas.signEndTime)
        res.datas.startTime1 = this.renderTime(res.datas.startTime)
        res.datas.endTime1 = this.renderTime(res.datas.endTime)
        this.datas = res.datas;
        setInterval(this.scroll,1000)
      });
    },
    curPage(e) {

    },
    renderTime(date) {
        let arr = [];
        var dateee = new Date(date)
        arr.push(dateee.getFullYear())
        arr.push(dateee.getMonth()+1)
        arr.push(dateee.getDate())
        return arr;
    },
    renderTime(date) {
      let datea = date.split(/[- : \/]/)
      console.log(datea[0]+datea[1]+datea[2])
      return datea[0]+'-'+datea[1]+'-'+datea[2].slice(0,2)
    },
    watchScroll() {
            if (this.$route.meta.fixedNav === false) {
                return false;
            }
            // 滚动的距离
            var scrollTop =
                window.pageYOffset ||
                document.documentElement.scrollTop ||
                document.body.scrollTop

            // 容器的高度
            var offsetTop = document.querySelector('#nav').offsetHeight

            // console.log('scrollTop=>', scrollTop, '  offsetTop=>', offsetTop)

            //  滚动的距离如果大于了元素到顶部的距离时，实现吸顶效果
            if (scrollTop > offsetTop) {
                this.navBarFixed = true
            } else {
                this.navBarFixed = false
            }
        },
      scroll(){
       this.animate=true;    // 因为在消息向上滚动的时候需要添加css3过渡动画，所以这里需要设置true
       setTimeout(()=>{      //  这里直接使用了es6的箭头函数，省去了处理this指向偏移问题，代码也比之前简化了很多
               this.datas.signList.push(this.datas.signList[0]);  // 将数组的第一个元素添加到数组的
               this.datas.signList.shift();               //删除数组的第一个元素
               this.animate=false;  // margin-top 为0 的时候取消过渡动画，实现无缝滚动
       },500)
    }
  },
};
</script>
<style>
.qrcode img{
    background: pink;
    margin: auto;
    margin-top: 10px;
}
</style>
<style scoped>
.index {
  background: #fff;
}
.wrap{
  padding: 50px 0;
}
.wrapa{
  width: 1200px;
  margin: auto;
  padding: 10px 0;
}
.content{
  width: 842px;
  flex-shrink: 0;
  flex-grow: 0;
  padding-right: 36px;
}
.top{
  padding:0 170px;
  margin: auto;
  text-align: center;
  border-bottom: 1px solid #EEEEEE;
}
.top .title{
  font-size: 26px;
  line-height: 40px;
  font-weight: bold;
  position: relative;
}
.top .title .qrcode{
  position: absolute;
  top: 8px;
  right: -60px;
  width: 60px;
  height: 60px;
}
.top .date{
  font-size: 14px;
  color: #bbb;
  line-height: 30px;
  padding: 10px 0 30px 0;
}
.mian{
  padding: 30px 2px;
  border-bottom: 1px solid #EEEEEE;
  line-height: 180%;
}
.right{
  width: 320px;
  height: 435px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0px 0px 10px 0px #DEDEDE;
  box-sizing: border-box;
  padding: 25px;
}
.right{
  width: 320px;
  height: 480px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0px 0px 10px 0px #DEDEDE;
  box-sizing: border-box;
  padding: 25px;
}
.right b{
  flex-shrink: 0;
  flex-grow: 0;
}
.right .right-title{
  padding-bottom: 20px;
}
.right .right-title b{
  width: 4px;
  height: 18px;
  background: #3DABC4;
  margin-right: 8px;
}
.right .right-title p{
  font-size: 16px;
  color: #3DABC4;
  line-height: 18px;
  font-weight: bold;
}
.right .p{
  font-size: 14px;
  color: #777;
  line-height: 30px;
  padding: 8px 0;
}
.right .p p{
  color: #333333;
}
.right .btn{
  width: 178px;
  height: 40px;
  line-height: 40px;
  background-color: #3DABC4;
  color: #fff;
  font-size: 14px;
  text-align: center;
  border-radius: 3px;
  margin: 20px auto 0;
}
.right-scroll{
  width: 320px;
  height: 320px;
  margin-top: 30px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0px 0px 10px 0px #DEDEDE;
  box-sizing: border-box;
  padding: 25px;
}
.right-scroll .right-title b{
  width: 4px;
  height: 18px;
  background: #3DABC4;
  margin-right: 8px;
}
.right-scroll .right-title p{
  font-size: 16px;
  color: #3DABC4;
  line-height: 18px;
  font-weight: bold;
}
#box{
    margin-top: 10px;
    width: 100%;
    height: 240px;
    overflow: hidden;
}
.anim{
    transition: all 0.5s;
    margin-top: -36px;
}
#con1 li{
    list-style: none;
    line-height: 36px;
    height: 36px;
}
</style>
